import time

from selenium import webdriver

# 设置请求头
headers = {
    'User-Agent':' Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36'
}

# 设置代理
proxy = 'https://dps.kdlapi.com/api/getdps/?secret_id=o8dwnxxu6fy8d25y7mvw&num=1&signature=n86gw540grw65csznaz351noortcx83q&pt=1&sep=1'

# 创建Chrome WebDriver，并设置请求头和代理
driver = webdriver.Chrome()

# 加载网址
driver.get("https://kns.cnki.net/kns8/defaultresult/index")
driver.maximize_window()

# 输入搜索关键词

driver.find_element_by_xpath("//input[@id='txt_search']").send_keys('爬虫')
driver.find_element_by_xpath("//input[@class='search-btn']").click()
time.sleep(3)
while True:
    time.sleep(5)
    time.sleep(2)
    book_name=driver.find_element_by_xpath("//div[@id='gridTable']/table[@class='result-table-list']").text
    # 在这里添加翻页逻辑或者其他退出循环的条件
    print(book_name)
    driver.find_element_by_xpath("//div[@class='pages']/a[@id='PageNext']").click()
driver.find_element_by_id('changeVercode')
time.sleep(20)





